package xyz.weizhi.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import xyz.weizhi.tanhua.dubbo.mapper.UserInfoMapper;
import xyz.weizhi.tanhua.model.domain.UserInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author milian
 * @Date 2021/10/22 0022 19:28
 */
@DubboService
public class UserInfoApiImpl implements UserInfoApi {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo selectByid(Long id) {
        return userInfoMapper.selectById(id);
    }

    @Override
    public UserInfo findById(Long userID) {
        return userInfoMapper.selectById(userID);
    }

    @Override
    public Map<Long, UserInfo> findByIds(List<Long> userIds, UserInfo userInfo) {
        QueryWrapper<UserInfo> qw = new QueryWrapper<>();
        if (userInfo!=null) {
            qw.lt("age", userInfo.getAge());
            qw.eq("gender", userInfo.getGender());
        }
        qw.in("id", userIds);
        List<UserInfo> userInfos = userInfoMapper.selectList(qw);
        Map<Long, UserInfo> map = new HashMap<>();
        userInfos.stream().forEach(e->{
            map.put(e.getId(), e);
        });
        return map;
    }
}